const bcrypt = require('bcrypt')

// 获取加密的密码
const getBcryptPwd = (myPlaintextPassword) => {
  return new Promise((resolve, reject) => {
    bcrypt.genSalt(10, function(err, salt) {
      bcrypt.hash(myPlaintextPassword, salt, function(err, hash) {
        // Store hash in your password DB.
        if (err) {
          reject(err)
        } {
          resolve(hash)
        }
      });
    });
  })
}

// 验证密码
const getComparePwd = (password, myPlaintextPassword) => {
  return new Promise((resolve, reject) => {
    bcrypt.compare(password, myPlaintextPassword, function(err, hash) {
      // Store hash in your password DB.
      if (err) {
        reject(err)
      } {
        resolve(hash)
      }
    });
  })
}

module.exports = {
  getBcryptPwd,
  getComparePwd
}
